#include <iostream>
using namespace std;
int n = 4;
int data[4] = {5, 2, 1, 4};

// dfs
void swap(int i, int j){
    if(i == j) return;
    int temp = data[j];
    data[j] = data[i];
    data[i] = temp;
}
int cnt = 0;
void dfs(int begin, int end){
    if(begin == end){
        for(int i = 0; i < end; i++){
            cout<<data[i]<<" ";
        }
        cout<<endl;
        cnt++;
        return;
    }
    for(int j = begin; j < n; j++){
        swap(begin, j);
        dfs(begin + 1, end);
        swap(begin, j);
    }
}


int main(){
    int m = 3;
    dfs(0, m);
    cout<<"\n共"<<cnt<<"种"<<endl;//Anm
    return 0;
}